package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Menuspicy;
import com.restaurant.service.MenuspicyService;

public class MenuspicyServiceImpl implements MenuspicyService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuspicy addOrModify( Menuspicy objMenuspicy ) {
       return ( Menuspicy ) hibernateTemplate.merge( objMenuspicy );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuspicy deleteRecord( Menuspicy objMenuspicy ) {
       hibernateTemplate.delete( objMenuspicy );
       return objMenuspicy;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuspicy modifyRecord( Menuspicy objMenuspicy ) {
       return ( Menuspicy ) hibernateTemplate.merge( objMenuspicy );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menuspicy> loadAll() {
       return (List<Menuspicy>)hibernateTemplate.findByNamedQuery( "Menuspicy.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuspicy loadByPrimaryKey( Long primaryKey ) {
       return (Menuspicy) hibernateTemplate.get( Menuspicy.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuspicy deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menuspicy> loadByHql(String query) {
       return ( List<Menuspicy> ) hibernateTemplate.find( query );
   }
}